package com.ruoyi.service;

import com.ruoyi.entity.SxfOrder;
import com.ruoyi.mapper.SxfOrderMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.SxfOrderFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 订单主表 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-30
 */
@Service
public class SxfOrderService extends ServiceImpl<SxfOrderMapper, SxfOrder> {

	public ResponseData create(SxfOrderFrom sxfOrder) {
		SxfOrder entity = transformationFrom(sxfOrder);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(SxfOrderFrom sxfOrder) {
		if(findById(sxfOrder.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfOrder entity = transformationFrom(sxfOrder);
		entity.setId(sxfOrder.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public SxfOrder transformationFrom(SxfOrderFrom sxfOrder) {
		SxfOrder entity = new SxfOrder();
		entity.setOrderSn(sxfOrder.getOrderSn());
		entity.setOrderType(sxfOrder.getOrderType());
		entity.setOrderDesc(sxfOrder.getOrderDesc());
		entity.setMobile(sxfOrder.getMobile());
		entity.setPreAmount(sxfOrder.getPreAmount());
		entity.setOnlinePaid(sxfOrder.getOnlinePaid());
		entity.setOfflinePaid(sxfOrder.getOfflinePaid());
		entity.setAmount(sxfOrder.getAmount());
		entity.setActualAmount(sxfOrder.getActualAmount());
		entity.setMerchantDiscountAmount(sxfOrder.getMerchantDiscountAmount());
		entity.setPlatformDiscountAmount(sxfOrder.getPlatformDiscountAmount());
		entity.setDiscountAmount(sxfOrder.getDiscountAmount());
		entity.setIntegral(sxfOrder.getIntegral());
		entity.setPriceSystemCode(sxfOrder.getPriceSystemCode());
		entity.setPayStatus(sxfOrder.getPayStatus());
		entity.setPayExpireTime(sxfOrder.getPayExpireTime());
		entity.setPaySerialNumber(sxfOrder.getPaySerialNumber());
		entity.setPrePayTime(sxfOrder.getPrePayTime());
		entity.setPayTime(sxfOrder.getPayTime());
		entity.setCancelTime(sxfOrder.getCancelTime());
		entity.setOrderStatus(sxfOrder.getOrderStatus());
		entity.setInvoiceStatus(sxfOrder.getInvoiceStatus());
		entity.setReservePaySn(sxfOrder.getReservePaySn());
		entity.setPropertyWithdrawChannel(sxfOrder.getPropertyWithdrawChannel());
		entity.setLeavePaySn(sxfOrder.getLeavePaySn());
		entity.setAppId(sxfOrder.getAppId());
		entity.setPayAppId(sxfOrder.getPayAppId());
		entity.setWithdrawChannel(sxfOrder.getWithdrawChannel());
		entity.setPayChannel(sxfOrder.getPayChannel());
		entity.setClearingStatus(sxfOrder.getClearingStatus());
		entity.setCreateTime(sxfOrder.getCreateTime());
		entity.setModifyTime(sxfOrder.getModifyTime());
		entity.setOrderId(sxfOrder.getOrderId());
		return entity;
	}

	public SxfOrderFrom transformationBean(SxfOrder sxfOrder) {
		SxfOrderFrom from = new SxfOrderFrom();
		from.setOrderSn(sxfOrder.getOrderSn());
		from.setOrderType(sxfOrder.getOrderType());
		from.setOrderDesc(sxfOrder.getOrderDesc());
		from.setMobile(sxfOrder.getMobile());
		from.setPreAmount(sxfOrder.getPreAmount());
		from.setOnlinePaid(sxfOrder.getOnlinePaid());
		from.setOfflinePaid(sxfOrder.getOfflinePaid());
		from.setAmount(sxfOrder.getAmount());
		from.setActualAmount(sxfOrder.getActualAmount());
		from.setMerchantDiscountAmount(sxfOrder.getMerchantDiscountAmount());
		from.setPlatformDiscountAmount(sxfOrder.getPlatformDiscountAmount());
		from.setDiscountAmount(sxfOrder.getDiscountAmount());
		from.setIntegral(sxfOrder.getIntegral());
		from.setPriceSystemCode(sxfOrder.getPriceSystemCode());
		from.setPayStatus(sxfOrder.getPayStatus());
		from.setPayExpireTime(sxfOrder.getPayExpireTime());
		from.setPaySerialNumber(sxfOrder.getPaySerialNumber());
		from.setPrePayTime(sxfOrder.getPrePayTime());
		from.setPayTime(sxfOrder.getPayTime());
		from.setCancelTime(sxfOrder.getCancelTime());
		from.setOrderStatus(sxfOrder.getOrderStatus());
		from.setInvoiceStatus(sxfOrder.getInvoiceStatus());
		from.setReservePaySn(sxfOrder.getReservePaySn());
		from.setPropertyWithdrawChannel(sxfOrder.getPropertyWithdrawChannel());
		from.setLeavePaySn(sxfOrder.getLeavePaySn());
		from.setAppId(sxfOrder.getAppId());
		from.setPayAppId(sxfOrder.getPayAppId());
		from.setWithdrawChannel(sxfOrder.getWithdrawChannel());
		from.setPayChannel(sxfOrder.getPayChannel());
		from.setClearingStatus(sxfOrder.getClearingStatus());
		from.setCreateTime(sxfOrder.getCreateTime());
		from.setModifyTime(sxfOrder.getModifyTime());
		from.setOrderId(sxfOrder.getOrderId());

		return from;
	}

	
	public SxfOrderFrom findById(String id) {
		SxfOrder entity = this.getOne(new QueryWrapper<SxfOrder>().lambda()
				.eq(SxfOrder::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfOrder sxfOrder = new SxfOrder();
		sxfOrder.setId(id);
		this.updateById(sxfOrder);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, SxfOrderFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<SxfOrder>().lambda()
				.eq(StringUtils.isNotEmpty(ibean.getOrderSn()), SxfOrder::getOrderSn, ibean.getOrderSn())
				.eq(StringUtils.isNotEmpty(ibean.getOrderType()), SxfOrder::getOrderType, ibean.getOrderType())
				.eq(StringUtils.isNotEmpty(ibean.getOrderDesc()), SxfOrder::getOrderDesc, ibean.getOrderDesc())
				.eq(StringUtils.isNotEmpty(ibean.getMobile()), SxfOrder::getMobile, ibean.getMobile())
				.eq(ibean.getPreAmount() != null, SxfOrder::getPreAmount, ibean.getPreAmount())
				.eq(ibean.getOnlinePaid() != null, SxfOrder::getOnlinePaid, ibean.getOnlinePaid())
				.eq(ibean.getOfflinePaid() != null, SxfOrder::getOfflinePaid, ibean.getOfflinePaid())
				.eq(ibean.getAmount() != null, SxfOrder::getAmount, ibean.getAmount())
				.eq(ibean.getActualAmount() != null, SxfOrder::getActualAmount, ibean.getActualAmount())
				.eq(ibean.getMerchantDiscountAmount() != null, SxfOrder::getMerchantDiscountAmount, ibean.getMerchantDiscountAmount())
				.eq(ibean.getPlatformDiscountAmount() != null, SxfOrder::getPlatformDiscountAmount, ibean.getPlatformDiscountAmount())
				.eq(ibean.getDiscountAmount() != null, SxfOrder::getDiscountAmount, ibean.getDiscountAmount())
				.eq(ibean.getIntegral() != null, SxfOrder::getIntegral, ibean.getIntegral())
				.eq(StringUtils.isNotEmpty(ibean.getPriceSystemCode()), SxfOrder::getPriceSystemCode, ibean.getPriceSystemCode())
				.eq(StringUtils.isNotEmpty(ibean.getPayStatus()), SxfOrder::getPayStatus, ibean.getPayStatus())
				.eq(ibean.getPayExpireTime() != null, SxfOrder::getPayExpireTime, ibean.getPayExpireTime())
				.eq(StringUtils.isNotEmpty(ibean.getPaySerialNumber()), SxfOrder::getPaySerialNumber, ibean.getPaySerialNumber())
				.eq(ibean.getPrePayTime() != null, SxfOrder::getPrePayTime, ibean.getPrePayTime())
				.eq(ibean.getPayTime() != null, SxfOrder::getPayTime, ibean.getPayTime())
				.eq(ibean.getCancelTime() != null, SxfOrder::getCancelTime, ibean.getCancelTime())
				.eq(StringUtils.isNotEmpty(ibean.getOrderStatus()), SxfOrder::getOrderStatus, ibean.getOrderStatus())
				.eq(StringUtils.isNotEmpty(ibean.getInvoiceStatus()), SxfOrder::getInvoiceStatus, ibean.getInvoiceStatus())
				.eq(StringUtils.isNotEmpty(ibean.getReservePaySn()), SxfOrder::getReservePaySn, ibean.getReservePaySn())
				.eq(StringUtils.isNotEmpty(ibean.getPropertyWithdrawChannel()), SxfOrder::getPropertyWithdrawChannel, ibean.getPropertyWithdrawChannel())
				.eq(StringUtils.isNotEmpty(ibean.getLeavePaySn()), SxfOrder::getLeavePaySn, ibean.getLeavePaySn())
				.eq(ibean.getAppId() != null, SxfOrder::getAppId, ibean.getAppId())
				.eq(ibean.getPayAppId() != null, SxfOrder::getPayAppId, ibean.getPayAppId())
				.eq(StringUtils.isNotEmpty(ibean.getWithdrawChannel()), SxfOrder::getWithdrawChannel, ibean.getWithdrawChannel())
				.eq(StringUtils.isNotEmpty(ibean.getPayChannel()), SxfOrder::getPayChannel, ibean.getPayChannel())
				.eq(StringUtils.isNotEmpty(ibean.getClearingStatus()), SxfOrder::getClearingStatus, ibean.getClearingStatus())
				.eq(ibean.getCreateTime() != null, SxfOrder::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifyTime() != null, SxfOrder::getModifyTime, ibean.getModifyTime())
				.eq(ibean.getOrderId() != null, SxfOrder::getOrderId, ibean.getOrderId())
				);
	}
}
